package org.sintek.poc.dictionary;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;

import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;

public class ContentLoader {

	private static ContentLoader instance;
	private Dictionary<String, String> dictionary;
	private Properties contentLoaderConfig;
	private File wordListFile;

	private ContentLoader() throws Exception {
		initialize();
	}

	public void initialize() throws Exception {
		dictionary = new Hashtable<String, String>();
		contentLoaderConfig = new Properties();

		contentLoaderConfig.load(ContentLoader.class
				.getResourceAsStream("/config.properties"));

		String wordListPath = contentLoaderConfig
				.getProperty("mycom.dictionary.file");

		wordListFile = new File(wordListPath);

		System.out.println(wordListPath);
		this.loadDictionay();
	}

	public static synchronized ContentLoader getInstance() throws Exception {
		if (instance == null) {
			instance = new ContentLoader();
		}
		return instance;
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public Dictionary<String, String> loadDictionay() {
		dictionary = new Hashtable<String, String>();
		try {
			
			
			 NPOIFSFileSystem fs = new NPOIFSFileSystem(wordListFile);
			 
			  HSSFWorkbook wb = new HSSFWorkbook(fs.getRoot(), false);

		} catch (FileNotFoundException e) {
			e.printStackTrace();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			// fileInputStream.close();
		}
		return dictionary;
	}

	public String search(String word) {
		return null;
	}
}
